package com.systec.smalltools.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author cmd
 */
public class FileUtils {
    /**
     * 获取流文件读取前端传递的file
     *
     * @param ins
     * @param file
     */

    public static void inputStreamToFile(InputStream ins, File file) {
//        读取长度
        int len = 8192;
        try {
            OutputStream os = new FileOutputStream(file);
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            while ((bytesRead = ins.read(buffer, 0, len)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            os.close();
            ins.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
